import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter);
const originalPush = VueRouter.prototype.push;

VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch(err => err);
};

const routes = [{
    path: '/',
    name: 'home',
    component: () => import('../views/homeView.vue'),
    meta: {
      index: 0
    },
  },
  {
    path: '/rank',
    name: 'rank',
    redirect: '/rank/riman',
    component: () => import('../views/rankView.vue'),
    meta: {
      index: 1
    },
    children: [{
        path: '/rank/riman',
        name: 'riman',
        component: () => import('@/components/rimanCom.vue'),

      },
      {
        path: '/rank/guoman',
        name: 'guoman',
        component: () => import('@/components/guomanCom.vue'),

      }, {
        path: '/rank/free',
        name: 'free',
        component: () => import('@/components/freeCom.vue'),
      },
    ]
  },
  {
    path: '/classify',
    name: 'classify',
    component: () => import('../views/classifyView.vue'),
    redirect: '/classify',
    meta: {
      index: 2
    },
    children: [{
      path: '/classify',
      name: 'all',
      component: () => import('@/components/classifyCom.vue'),
    }, ]
  },

  {
    path: '/my',
    name: 'my',
    component: () => import('../views/loginView.vue'),
    redirect: '/my',
    children: [{
      path: '/my',
      name: 'login',
      component: () => import('@/components/loginCom.vue'),
    }, ],
    meta: {
      index: 3
    }
  },
  {
    path: '/detail',
    name: 'detail',
    component: () => import('@/components/detailCom.vue')
  },
  {
    path: '/cartoon',
    name: 'cartoon',
    component: () => import('@/components/cartoonCom.vue')
  },
  {
    path: '/lazy',
    name: 'lazy',
    component: () => import('@/components/lazyCom.vue')
  }
]

const router = new VueRouter({
  mode: 'hash',
  routes,
  // linkActiveClass: 'active'
})


export default router